#!/bin/bash
# Author: Xun Deng

op=${1:-s}

function setEnvs() {
    export DXOS_OSNAME='dxos'
    export DXOS_KERNEL_BASEURL='https://mirrors.tuna.tsinghua.edu.cn/kernel/v5.x/' # to download "linux-${DXOS_KERNEL_VERSION}.tar.xz"
    export DXOS_KERNEL_VERSION='5.14.1'
    export DXOS_GRUB_CORE_VERSION='2.06~rc1' # to download "grub-${DXOS_GRUB_CORE_VERSION}.tar.xz"
    export DXOS_GRUB_DEVICE='/dev/sdb'       # MBR on "${DXOS_GRUB_DEVICE}1"

    # update .config
    if [ -f '.config' ]; then
        sed -i "s/^CONFIG_DEFAULT_HOSTNAME=.*$/CONFIG_DEFAULT_HOSTNAME=\"${DXOS_OSNAME}\"/g" '.config'
    fi
}

chmod +x *.sh

case $op in
s | S) # set (default)
    echo 'set environment variables DXOS_*'
    setEnvs
    ;;
r | R) # remove
    echo 'remove environment variables DXOS_*'
    for k in $(env | grep DXOS_ | awk -F '=' '{print($1)}'); do
        export -n $k
    done
    ;;
esac
